package com.huanghao.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.huanghao.pojo.Commod;
import com.huanghao.pojo.Result;
import com.huanghao.pojo.User;

@RestController
public class UserController {

	@Autowired
    private com.huanghao.Service.UserService userService;
	
	//查询
	@GetMapping("user.do")
	public Result list() {
		System.out.println("查询");
		List<User> userList = userService.list();
		return Result.success(userList);
	}
	
	//根据用户编号查询
	@GetMapping("user.do/{id}")
    public Result getById(@PathVariable Integer id){
    	System.out.println("查询id为"+id+"的信息");
        User user   = userService.getById(id);
        return Result.success(user);
    }
	
	//删除
	@DeleteMapping("user.do/{id}")
    public Result delete(@PathVariable Integer id){
		System.out.println("删除id为"+id+"的用户");
        userService.delete(id);
        return Result.success();
    }
	
	@PostMapping("user.do")
	public Result add( User user) {
		System.out.println("新增用户");
		userService.add(user);
		return Result.success();
	}
	
	@PutMapping("user.do")
	public Result update( User user) {
		System.out.println("修改用户信息（除密码）");
		userService.update(user);
		return Result.success();
	}
}
